//
//  CSSStatusToolBar.swift
//  weibo28
//
//  Created by chushushan on 16/5/14.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class CSSStatusToolBar: UIView {


    
    //懒加载button
    //转发button
    private lazy var retweetButton: UIButton = self.addChildButton("timeline_icon_retweet", title: "转发")
    //评论button
    private lazy var commentButton: UIButton = self.addChildButton("timeline_icon_comment", title: "评论")
    //点赞
    private lazy var unlikeButton: UIButton = self.addChildButton("timeline_icon_unlike", title: "赞")
    
    
    var statusViewModel: CSSStatusViewModel? {
        
        didSet {
        
            retweetButton.setTitle(statusViewModel?.retweetCountContent, forState: .Normal)
            commentButton.setTitle(statusViewModel?.commentCountContent, forState: .Normal)
            unlikeButton.setTitle(statusViewModel?.unlikeCountContent, forState: .Normal)
        
        }
    }
    
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        //添加子控件
        setupUI()
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    private func setupUI() {
        
        
      
        //设置按钮的约束
        retweetButton.snp_makeConstraints { (make) -> Void in
            make.top.leading.bottom.equalTo(self)
            make.width.equalTo(commentButton)
        }
        
        commentButton.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton.snp_trailing)
            make.width.equalTo(unlikeButton)
        }
        
        unlikeButton.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(commentButton.snp_trailing)
            make.trailing.equalTo(self)
        }
        
        
        let firstLineView = addChildLineView()
        let secondLineView = addChildLineView()
        
        firstLineView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton.snp_trailing)
            make.centerY.equalTo(self)
            

            
        }
    
        secondLineView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentButton.snp_trailing)
            make.centerY.equalTo(self)

        }
    }
    
    
    //按钮样式方法
    private func addChildButton(imageName: String, title: String) -> UIButton {
    
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: .Normal)
    
        button.setTitle(title, forState: .Normal)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        button.setTitleColor(UIColor.grayColor(), forState: .Normal)
        
        //取消按钮点击高亮背景颜色
        //1.
//        button.backgroundColor = UIColor(patternImage: UIImage(named: "timeline_card_bottom_background")!)
        //2
        button.adjustsImageWhenHighlighted = false
        
        addSubview(button)
        return button
    }
    
    
    
    //创建线
    private func addChildLineView() -> UIView {
        
        let view = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(view)
        return view
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    

}
